<template>
    <!-- 现场旁站记录列表 -->
    <base-breadcrumb>
        <searchData :searchData="searchOptions" @search="handleSearch" />
        <div class="page-body">
            <a-card :bordered="false">
                <!-- <title-name title="现场旁站记录" /> -->
                <!-- 机械设备列表统计 -->
                <div class="table-operateors mb20">
                    <div class="pub-table-select-count">
                        <a-icon type="info-circle" theme="twoTone" />
                        <span>
                            旁站记录总数：
                            <a>{{ num }}</a
                            >个
                        </span>
                    </div>
                </div>
                <list-table
                    ref="table"
                    size="default"
                    rowKey="id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    showPagination="auto"
                >
                    <span slot="sort" slot-scope="text, record, index">{{ index + 1 }}</span>
                    <span slot="auditStatus" slot-scope="text, record">
                        <list-status :status="record.auditStatus" conversion="en" :text="text"></list-status>
                    </span>
                    <template slot="operator" slot-scope="text, record">
                      <div  class="pub-table-list-action">
                        <span class="base-btn" @click="handleUpdate('look', record)">查看</span>
                        <span class="base-btn" @click="handleDel( record.id)" v-if="hideBuquBtn()">删除</span>
                        <!-- <a-divider type="vertical" />
            <a class="base-btn" @click="handleUpdate('edit', record)">编辑</a> -->
                      </div>
                    </template>
                </list-table>
            </a-card>
        </div>
    </base-breadcrumb>
</template>

<script>
import StatusDisplay from '@/components/StatusDisplay'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { STable } from '@/components'
import ThemeChoose from '@/components/themeChoose/themeChoose.vue'
import { del, getSideStandList } from '@/api/safetySupervision/side.js'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import Vue from 'vue'
const searchOptions = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '分包商名称',
        keyValue: 'searchQuery._checked',
        valueKey: 'subContractId',
        type: SelectSubcontractor,
    },
    {
        name: '旁站部位',
        value: 'sideStandPart',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'leadTime',
        type: 'dateRange',
    },
]

const columns = [
    {
        title: '序号',
        dataIndex: 'sort',
        scopedSlots: { customRender: 'sort' },
        width:80,
    },
    {
        title: '旁站内容',
        dataIndex: 'sideStandContent',
        width:300,
    },
    {
        title: '旁站部位',
        dataIndex: 'sideStandPart',
        width:150,
    },
    {
        title: '作业人数',
        dataIndex: 'workerQuantity',
        width:100,
    },
    {
        title: '作业单位',
        dataIndex: 'subContractName',
        width:200,
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
        width:200,
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
        width:200,
    },
    {
        title: '填报时间',
        dataIndex: 'sidStandDate',
        width:150,
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' },
        width:100,
    },
    {
        title: ' 操作',
        dataIndex: 'operator',
        width:150,
        scopedSlots: { customRender: 'operator' },
    },
]
export default {
    name:'a'+Date.now(),
  components: {
        ThemeChoose,
        STable,
        StatusDisplay,
    },
    data() {
        return {
            searchOptions: searchOptions,
            formConfig: {},
            state: {
                isExpand: false,
            },
            formInfo: this.$form.createForm(this, { name: 'searchForm' }),
            columns: columns,
            queryParam: {},
            num: '',
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                const [err, res] = await getSideStandList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        this.num = res.totalSize
                        resolve(res)
                    }
                })
            },
        }
    },
    methods: {
        handleSearch(val = {}) {
            this.queryParam = {
                ...val,
                beginTime: (val.leadTime && val.leadTime.length && val.leadTime[0].format('YYYY-MM-DD')) || void 0,
                endTime: (val.leadTime && val.leadTime.length && val.leadTime[1].format('YYYY-MM-DD')) || void 0,
            }
            this.$refs.table.refresh(true)
        },
        // 处理更新操作（新增、编辑）
        handleUpdate(type, data = {}) {
            this.$router.push({
                name: 'sideDetail',
                query: {
                    id: data.id || '',
                    pageType: type,
                },
            })
        },
      handleDel(id){
          this.$delList3(del,()=>{
            this.handleSearch()
          },{id})
      }
    },
}
</script>

<style lang="less" scoped>
.page-header {
    .header-row {
        display: flex;
        .flex-content {
            flex: auto;
        }
        .divider {
            margin: 0 12px;
        }
        .expand-btn {
            margin-left: 8px;
            font-size: 14px;
        }
    }
}
.page-body {
    .table-operateors {
        .ant-btn + .ant-btn {
            margin-left: 12px;
        }
    }
}
</style>
